package com.lhd.mpaas.demo.adapter;

import android.content.Context;
import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lhd.mpaas.demo.R;
import com.lhd.mpaas.demo.model.HomeMenuBean;

import java.util.List;

public class HomeMenuAdapter extends BaseQuickAdapter<HomeMenuBean, BaseViewHolder> {

    private Context mContext;

    public HomeMenuAdapter(Context context, int layoutResId, @Nullable List<HomeMenuBean> data) {
        super(layoutResId, data);
        mContext = context;
    }

    @Override
    protected void convert(final BaseViewHolder helper, final HomeMenuBean item) {
        helper.setText(R.id.tv_name, item.getName());
        //获取资源图片
        int drawableId = mContext.getResources().getIdentifier(item.getIconUrl(), "mipmap", mContext.getPackageName());

        if (0 == drawableId) {
            drawableId = R.mipmap.ic_launcher;
        }

        helper.setImageResource(R.id.iv_icon, drawableId);
    }
}
